package com.example.tnevaluate.controller;

import com.example.tnevaluate.service.impl.CommentServiceImpl;
import com.yc.biz.BizException;
import com.yc.pojo.Comment;
import com.yc.pojo.CommentDTO;
import com.yc.vo.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 廖老师
 * @since 2023-07-28
 */
@RestController
@RequestMapping("comment")
public class CommentController {

    @Resource
    CommentServiceImpl commentService;

    @RequestMapping("selectComments")
    List selectComments(Integer houseId){
        List<CommentDTO> list = null;
        try {
            list = commentService.selectComments(houseId);
        } catch (BizException e) {
            e.printStackTrace();
        }
        return list;
    }

    @RequestMapping("insertComment")
    Result insertComment(Integer houseId, String content, Integer userId) {
        try {

            commentService.insertComment(houseId, content, userId);
            return Result.success("评论发表成功!");
        } catch (BizException e) {
            e.printStackTrace();
            return Result.failure(e.getMessage());
        }
    }
}

